package queue;

import arrary.Array;

/**
 * @author zhaoziqiang
 * @Description:
 * @date 2020/8/17 19:35
 */
public class ArrQueue<E> implements Queue<E> {
    private Array<E> array;

    public ArrQueue(int capacity) {
        array = new Array<>(capacity);
    }

    public ArrQueue() {
        array = new Array<>();
    }

    @Override
    public void enqueue(E e) {
        array.addLast(e);
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public int getCapacity() {
        return array.getCapacity();
    }

    @Override
    public E dequeue() {
        return array.removeFirst();
    }

    @Override
    public E getHead() {
        return array.getFirst();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Queue: size=" + array.getSize() + "\n");
        sb.append("head [");
        for (int i = 0; i < array.getSize(); i++) {
            sb.append(array.get(i));
            if (i != array.getSize() - 1)
                sb.append(",");
        }
        sb.append("]");
        sb.append(" tail");
        return sb.toString();
    }

    public static void main(String[] args) {

        ArrQueue<Integer> queue = new ArrQueue<>();
        for (int i = 0; i < 10; i++) {
            queue.enqueue(i);
            if (i % 3 == 0)
                queue.dequeue();
            System.out.println(queue);
        }
        System.out.println(queue);
        Integer leder = queue.getHead();
        System.out.println(leder);
    }
}
